package model;

import java.util.Date;

/**
 * represent the basic result of the execution of a solver or preprocessor 
 * @author stephane
 *
 */
public class BasicResult {
	public static final String DEFAULT_DESCRIPTION = "Result";
	public static final String DEFAULT_STDERR = "Nothing";
	public static final String DEFAULT_STDIN = "Nothing";
	public static final String DEFAULT_UNKNOW = "Unknow";
	
	
	protected Date begin = new Date(); 
	protected Date end = new Date(Long.MAX_VALUE);
	protected int timeout = -1;//en ms
	protected String memoryUsed = DEFAULT_UNKNOW;
	protected int exitVal = 0;
	protected String stderr = DEFAULT_STDERR;
	protected String stdin = DEFAULT_STDERR;
	protected String description = DEFAULT_DESCRIPTION;
	

	public String getMemoryUsed() {
		return memoryUsed;
	}

	public void setMemoryUsed(String memoryUsed) {
		this.memoryUsed = memoryUsed;
	}
	
	public int getExitVal() {
		return exitVal;
	}

	public void setExitVal(int exitVal) {
		this.exitVal = exitVal;
	}

	public int getTimeout() {
		return timeout;
	}

	public void setTimeout(int timeout) {
		this.timeout = timeout;
	}

	public String getStderr() {
		return stderr;
	}

	public void setStderr(String stderr) {
		this.stderr = stderr;
	}
	
	public void addStderr(String stderr) {
		if(this.stderr.equals(DEFAULT_STDERR))
			this.stderr = stderr;
		else
			this.stderr += stderr;
	}

	public String getStdin() {
		return stdin;
	}

	public void setStdin(String stdin) {
		this.stdin = stdin;
	}
	
	public void addStdin(String stdin) {
		if(this.stdin.equals(DEFAULT_STDIN))
			this.stdin = stdin;
		this.stdin += stdin;
	}
	
	
	public Date getBegin() {
		return begin;
	}

	public void setBegin(long begin) {
		if(begin <= end.getTime() && begin >= 0)
			this.begin.setTime(begin);
		else
			throw new IllegalArgumentException();
	}

	public Date getEnd() {
		return end;
	}

	public void setEnd(long end) {
		if(end >= begin.getTime())
			this.end.setTime(end);
		else
			throw new IllegalArgumentException();
	}

	public long getPreprocTime() {
		return end.getTime() - begin.getTime();
	}

	public String getDescription() {
		return description;
	}

	public void setDescription(String description) {
		this.description = description;
	}
	
}
